package Server.ClientObj;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Logger;

public class ClientThread implements Runnable{
	private ServerSocket     serverSocket;
	private Socket           clientSocket;
	private Sender           sender;
	private String           name;
	
	private Logger logger = Logger.getLogger(ClientThread.class.getName());
	
	public ClientThread(ServerSocket serverSocket){
		this.serverSocket = serverSocket;
	}
	
	public void run() {
		try{
			while(true) {
				clientSocket = serverSocket.accept();
				new Receiver(this, clientSocket.getInputStream());
				sender = new Sender(clientSocket.getOutputStream());
				logger.info("Client Connected!" + ", IP:" + clientSocket.getLocalSocketAddress());
			}
		} catch (IOException e) {
				e.printStackTrace();
		}
	}
	
	public Sender getSender(){
		return sender;
	}
	
	public void setName(String name){
		this.name = name;
	}
	
	public String getName(){
		return name;
	}
}
